<template>
	<cl-crud ref="Crud">
		<cl-row>
			<!-- 刷新按钮 -->
			<cl-refresh-btn />
			<!-- 新增按钮 -->
			<cl-add-btn />
			<!-- 删除按钮 -->
			<cl-multi-delete-btn />
			<!-- 筛选状态 -->
			<cl-filter label="状态">
				<cl-select prop="status" :options="options.status" />
			</cl-filter>
			<cl-filter label="标题">
				<cl-search-key field="title" placeholder="搜索标题" :width="250" />
			</cl-filter>
			<cl-flex1 />
		</cl-row>
		<cl-row>
			<!-- 数据表格 -->
			<cl-table ref="Table" />
		</cl-row>
		<cl-row>
			<cl-flex1 />
			<!-- 分页控件 -->
			<cl-pagination />
		</cl-row>
		<!-- 新增、编辑 -->
		<cl-upsert ref="Upsert" />
	</cl-crud>
</template>

<script lang="ts" name="space-info" setup>
import { useCrud, useTable, useUpsert } from "@cool-vue/crud";
import { useCool } from "/@/cool";
import { reactive } from "vue";

const { service } = useCool();

// 选项
const options = reactive({
	status: [
		{ label: "未开始", value: "0" },
		{ label: "进行中", value: "1" },
		{ label: "已结束", value: "2" }
	]
});

// cl-upsert
const Upsert = useUpsert({
	items: [
		{
			label: "标题",
			prop: "title",
			component: { name: "el-input", props: { clearable: true } },
			required: true,
		},
		{
			label: "描述",
			prop: "description",
			component: { name: "el-input", props: { type: "textarea", rows: 4 } },
			required: true
		},
		{
			label: "价格",
			prop: "price",
			hook: "number",
			component: {
				name: "el-input-number", props: {
					"controls-position": "right"
				}
			},
			required: true,
			span: 8
		},
		{
			label: "年龄段",
			prop: "age_group",
			component: { name: "el-input", props: { clearable: true } },
			required: true,
			span: 8
		},
		{
			label: "活动时间",
			prop: "activity_time",
			component: {
				name: "el-date-picker",
				props: { type: "datetime", valueFormat: "YYYY-MM-DD HH:mm:ss" }
			},
			required: true,
			span: 8
		},
		{
			label: "集合地点",
			prop: "gathering_place",
			component: { name: "el-input", props: { clearable: true } },
			required: true,
			span: 8
		},
		{
			label: "人数",
			prop: "participant_count",
			hook: "number",
			component: {
				name: "el-input-number", props: {
					"controls-position": "right"
				}
			},
			required: true,
			span: 8
		},
		{
			label: "状态",
			prop: "status",
			component: { name: "el-radio-group", options: options.status, props: {} },
			value: [],
			required: true,
			span: 8
		},
		{
			label: "图片",
			prop: "img_url",
			component: { name: "cl-upload", props: { multiple: false } }
		},
		{
			label: "行程",
			prop: "itinerary",
			component: { name: "cl-editor-wang", props: { type: "textarea", rows: 4 } }
		},
		{
			label: "费用",
			prop: "fees",
			component: { name: "cl-editor-wang", props: { type: "textarea", rows: 4 } }
		},
		{
			label: "须知",
			prop: "notices",
			component: { name: "cl-editor-wang", props: { type: "textarea", rows: 4 } }
		},
		{ label: "省市区", prop: "pca", hook: "pca", component: { name: "cl-distpicker" } }
	]
});

// cl-table
const Table = useTable({
	columns: [
		{ type: "selection" },
		{ label: "标题", prop: "title", showOverflowTooltip: true, minWidth: 140 },
		{ label: "描述", prop: "description", showOverflowTooltip: true, minWidth: 200 },
		{ label: "价格", prop: "price", minWidth: 140 },
		{ label: "年龄段", prop: "age_group", minWidth: 140 },
		{
			label: "活动时间",
			prop: "activity_time",
			minWidth: 170,
			sortable: "custom",
			component: { name: "cl-date-text" }
		},
		{ label: "集合地点", prop: "gathering_place", minWidth: 140 },
		{ label: "人数", prop: "participant_count", minWidth: 140 },
		{ label: "状态", prop: "status", dict: options.status, dictColor: true, minWidth: 120 },
		{
			label: "图片",
			prop: "img_url",
			minWidth: 100,
			component: { name: "cl-image", props: { size: 60 } }
		},
		// { label: "行程", prop: "itinerary", showOverflowTooltip: true, minWidth: 200 },
		// { label: "费用", prop: "fees", showOverflowTooltip: true, minWidth: 200 },
		// { label: "须知", prop: "notices", showOverflowTooltip: true, minWidth: 200 },
		{
			label: "省市区",
			prop: "province",
			minWidth: 160,
			formatter(row) {
				return row.province + "-" + row.city + "-" + row.district;
			}
		},
		{
			label: "更新时间",
			prop: "updateTime",
			minWidth: 170,
			sortable: "custom",
			component: { name: "cl-date-text" }
		},
		{
			label: "创建时间",
			prop: "createTime",
			minWidth: 170,
			sortable: "desc",
			component: { name: "cl-date-text" }
		},
		{ type: "op", buttons: ["edit", "delete"] }
	]
});

// cl-crud
const Crud = useCrud(
	{
		service: service.space.info
	},
	(app) => {
		app.refresh();
	}
);

// 刷新
function refresh(params?: any) {
	Crud.value?.refresh(params);
}
</script>

<style scoped lang="scss"></style>
